<template>
  <div v-cloak>
    <div class="indexPage">
      <h1 class="title">出库管理系统</h1>
      <!-- 关闭按钮 -->
      <div class="close" @click="goToLogin">
        <img src="@/assets/close.png" alt="关闭" />
      </div>
      <!-- 主要内容  -->
      <div>
        <!-- 名字 -->
        <div class="userName">
          <h1>欢迎您，{{ name }}</h1>
          <img src="@/assets/gengduo.png" alt="图片" />
        </div>
        <!-- 发货列表 -->
        <div class="list">
          <van-row gutter="20">
            <van-col span="12">
              <van-badge class="item" :content="noDeliveryTotal">
                <div @click="goWebPage('/shipmentList')" class="listItem">
                  <img src="@/assets/indexPage1.png" alt="图片" />
                  <p>发货单</p>
                </div>
              </van-badge>
            </van-col>
            <van-col span="12">
              <van-badge class="item" :content="myDeliveryIngTotal">
                <div @click="goWebPage('/myShipment')" class="listItem">
                  <img src="@/assets/indexPage2.png" alt="图片" />
                  <p>我的发货</p>
                </div>
              </van-badge>
            </van-col>
          </van-row>
          <van-row gutter="20">
            <van-col span="12">
              <van-badge class="item" :content="completeDeliveryTotal">
                <div @click="goWebPage('/handoverList')" class="listItem">
                  <img src="@/assets/indexPage3.png" alt="图片" />
                  <p>出库交接</p>
                </div>
              </van-badge>
            </van-col>
            <van-col span="12">
              <van-badge class="item" :content="myHandoverIngTotal">
                <div @click="goWebPage('/myHandover')" class="listItem">
                  <img src="@/assets/indexPage4.png" alt="图片" />
                  <p>我的交接</p>
                </div>
              </van-badge>
            </van-col>
          </van-row>
          <van-row gutter="20">
            <van-col span="12">
              <van-badge class="item">
                <div @click="goWebPage('/damageRegistration')" class="listItem">
                  <img src="@/assets/indexPage5.png" alt="图片" />
                  <p>破损登记</p>
                </div>
              </van-badge>
            </van-col>
            <van-col span="12">
              <van-badge class="item">
                <div class="listItem" @click="tostMass">
                  <img src="@/assets/indexPage6.png" alt="图片" />
                  <p>其他功能</p>
                </div>
              </van-badge>
            </van-col>
          </van-row>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Vue from "vue";
import { Col, Row, Toast, Badge } from "vant";
import { getLocalhostUrl } from "@/utils/common";
import { getInfo, getHomeCount } from "@/services/api";
Vue.use(Toast);
Vue.use(Col);
Vue.use(Row);
Vue.use(Badge);

export default {
  data() {
    return {
      name: "",
      completeDeliveryTotal: 0,
      myDeliveryIngTotal: 0,
      myHandoverIngTotal: 0,
      noDeliveryTotal: 0,
    };
  },
  created() {
    this.getInfo();
    if (!window.timer) {
      window.getNoticeStatus();
    }
  },
  mounted() {
    window["reload"] = () => {
      this.getInfo();
    };
  },
  methods: {
    // 获取用户数据
    getInfo() {
      getInfo().then((res) => {
        if (res) {
          this.name = res.name;
          this.getHomeCount();
        }
      });
    },
    // 获取数量
    getHomeCount() {
      getHomeCount().then((res) => {
        if (res) {
          this.completeDeliveryTotal = res.completeDeliveryTotal;
          this.myDeliveryIngTotal = res.myDeliveryIngTotal;
          this.myHandoverIngTotal = res.myHandoverIngTotal;
          this.noDeliveryTotal = res.noDeliveryTotal;
        }
      });
    },
    // 温馨提示
    tostMass() {
      Toast("开发中...");
    },
    // 跳转页面
    goWebPage(url) {
      try {
        window.appPlat.goWebPage(getLocalhostUrl() + url);
      } catch (e) {
        this.$router.push(url);
      }
    },
    // 去登录页
    goToLogin() {
      if (window.timer) {
        clearInterval(window.timer);
      }
      this.$router.push("/login");
    },
  },
};
</script>
<style lang="scss" scoped>
.indexPage {
  width: 100%;
  background-image: url("~@/assets/indexPage_bg.png");
  background-size: 100%;
  background-repeat: no-repeat;
  background-position: top;
  position: relative;

  & > .title {
    font-size: 17px;
    font-weight: 600;
    color: #ffffff;
    line-height: 45px;
    text-align: center;
  }
  & > .close {
    width: 34px;
    height: 34px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    position: absolute;
    top: 5px;
    right: 5px;
    padding: 2px;
    box-sizing: border-box;
    img {
      width: 28px;
      height: 28px;
      display: block;
    }
  }

  .userName {
    position: absolute;
    top: 44px;
    left: 15px;
    background-color: rgba(45, 109, 149, 0.34);
    border-radius: 18px;
    padding: 5px 10px;
    box-sizing: border-box;

    & > h1 {
      font-size: 15px;
      font-weight: 400;
      color: #ffffff;
      line-height: 30px;
      display: inline-block;
    }

    & > img {
      width: 20px;
      margin: 5px 0;
      vertical-align: middle;
      display: inline-block;
    }
  }

  .list {
    width: 100%;
    margin-top: 150px;
    height: 200px;
    padding: 0 15px;
    box-sizing: border-box;
    .item {
      width: 100%;
      /deep/.van-badge {
        min-width: 30px;
        line-height: 27px;
        font-size: 18px;
      }
      .listItem {
        width: 100%;
        padding: 20px;
        box-sizing: border-box;
        background: #fff;
        border-radius: 15px;
        margin-bottom: 10px;

        img {
          width: 50px;
          display: block;
          margin: 0 auto 10px;
        }

        p {
          font-size: 18px;
          font-weight: 500;
          color: #333333;
          line-height: 2;
          text-align: center;
        }
      }
    }
  }
}
</style>
